package org.jeecg.modules.flow.api.fallback;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.flow.api.FlowBaseCloudApi;
import org.jeecg.modules.flow.entity.FlowAudit;
import org.jeecg.modules.flow.query.*;
import org.jeecg.modules.flow.vo.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Slf4j
public class FlowBaseCloudApiFallback implements FlowBaseCloudApi {

    @Setter
    private Throwable cause;

    @Override
    public Result<String> startInstanceByProKey(StartInstanceQuery query) {
        log.error("启动流程失败", cause);
        return Result.error("启动流程实例失败", null);
    }

    @Override
    public Result<ProInstanceVo> searchInstanceById(String InstanceId) {
        log.error("查询流程实例失败", cause);
        return Result.error("查询流程实例失败", null);
    }

    @Override
    public Result<List<ProInstanceVo>> searchInstanceByIds(Set<String> instanceIds) {
        log.error("查询流程实例列表失败", cause);
        return Result.error("查询流程实例列表失败", null);
    }

    @Override
    public Map<String, Object> getVariablesByTaskId(String taskId, List<String> variableNames, Boolean isHistory) {
        log.error("查询流程变量失败", cause);
        return null;
    }


    @Override
    public Result<Boolean> delInstanceById(String instanceId, String reason) {
        log.error("删除流程实例失败", cause);
        return Result.error("删除流程实例失败", null);
    }

    @Override
    public Result<List<TaskVo>> findTaskByAssignee(String assignee) {
        log.error("查询个人任务失败", cause);
        return Result.error("查询个人任务失败", null);
    }

    @Override
    public Result<List<TaskVo>> findTaskList(@RequestBody TaskQuery query) {
        log.error("查询任务失败列表", cause);
        return Result.error("查询任务失败列表", null);
    }

    @Override
    public Result<com.baomidou.mybatisplus.extension.plugins.pagination.Page<TaskVo>> findTasks(TaskQuery query, Integer pageNo, Integer pageSize) {
        return null;
    }

    @Override
    public Result<Boolean> submitTask(SubmitTaskQuery query) {
        log.error("提交任务失败", cause);
        return Result.error("提交任务失败", null);
    }

    @Override
    public ProInstanceVo getInstanceByBusinessKey(String businessKey) {
        log.error("获取流程实例失败", cause);
        return null;
    }

    @Override
    public TaskVo getActiveTaskByBusinessKey(String businessKey) {
        log.error("获取流程实例当前活动节点失败", cause);
        return null;
    }

    @Override
    public Result<Page<HistoryProcessInstanceVo>> queryHistoricProcessInstances(HistoryInstanceQuery query, Integer pageNo, Integer pageSize) {
        log.error("获取历史流程实例列表失败", cause);
        return Result.error("获取历史流程实例列表失败", null);
    }

    @Override
    public Result<Page<HistoryActivityInstanceVo>> queryHistoricActivityInstance(HistoryActivityQuery query, Integer pageNo, Integer pageSize) {
        log.error("获取历史活动流程实例列表失败", cause);
        return Result.error("获取历史活动流程实例列表失败", null);
    }

    @Override
    public Result<Page<HistoryTaskInstanceVo>> queryHistoricTaskInstances(HistoryTaskQuery query, Integer pageNo, Integer pageSize) {
        return null;
    }


    @Override
    public Result<List<FlowAudit>> queryAuditListByInstanceId(String processInstanceId) {
        log.error("根据流程实例获取审核意见信息失败", cause);
        return Result.error("根据流程实例获取审核意见信息失败", null);
    }

    @Override
    public Result<FlowAudit> queryAuditByTaskId(String taskId) {
        log.error("根据任务获取审核意见信息失败", cause);
        return Result.error("根据任务获取审核意见信息失败", null);
    }

    @Override
    public Result<?> timeOut(Long time) {
        log.error("微服务调用失败", cause);
        return Result.error("调用发送错误", 1);
    }

    @Override
    public Result<?> add(FlowAudit flowAudit) {
        return null;
    }


}
